/**
 * @date 4:32:32 PM
 * EducationAdminController.java
 * Administrator
 * TODO
 */
package com.qs.education.controllers;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.qs.education.bean.beans.EducationAdminResponse;
import com.qs.education.bean.beans.EducationTeacherResponse;
import com.qs.education.bean.enums.ResponseStatus;
import com.qs.education.service.IAdminAPIService;

/**
 * @class EducationAdminController
 * @author Brooks
 * @description
 * @date Oct 17, 2018
 */

@RestController
public class AdminController {
	@Autowired
	private IAdminAPIService iAdminService;

	private final Logger log = Logger.getLogger(this.getClass());

	/**
	 * @class 根据用户名和密码登录后台
	 * @author Brooks
	 * @description
	 * @date Oct 17, 2018
	 */
	@RequestMapping("/getAdminAPI")
	@ResponseBody
	public EducationAdminResponse getAdmin(HttpServletRequest request, String name, String password) {
		log.info("api getAdmin");
		EducationAdminResponse response = new EducationAdminResponse();
		response.setToken(response.getToken(request));
		response = iAdminService.getEducationAdmin(name, password);
		response.setStatus(ResponseStatus.SUCCESS.toString());
		return response;
	}

	/**
	 * 根据用户名查询用户信息
	 * 
	 * @author Arwen Liu
	 * @date 2018-11-01
	 * @param request HttpServletRequest
	 * @param name    用户名
	 * @return EducationAdminResponse
	 */
	@RequestMapping("/findAdminByName")
	@ResponseBody
	public EducationAdminResponse findAdminByName(HttpServletRequest request, String name) {
		log.info("api findAdminByName");
		EducationAdminResponse response = new EducationAdminResponse();
		response.setToken(response.getToken(request));
		response = iAdminService.findAdminByName(name);
		response.setStatus(ResponseStatus.SUCCESS.toString());
		return response;
	}
	
	/**
	 * @Description 更新管理员密码
	 * @author Jason
	 * @date Nov 15, 2018
	 * @param request
	 * @param name
	 * @return
	 */
	@RequestMapping("/updateAdminAPI")
	@ResponseBody
	public EducationAdminResponse updateAdmin(HttpServletRequest request, String name ,String oldPassword ,String newPassword) {
		
		log.info("api updateAdminAPI");
		EducationAdminResponse response = new EducationAdminResponse();
		response.setToken(response.getToken(request));
		response = iAdminService.updateAdmin(name,oldPassword,newPassword);
		response.setStatus(ResponseStatus.SUCCESS.toString());
		
		return response;
	}
}
